package com.shishuo.cms.service;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shishuo.cms.dao.ArticleCommentDao;
import com.shishuo.cms.entity.ArticleComment;
import com.shishuo.cms.entity.vo.ArticleCommentVo;
import com.shishuo.cms.entity.vo.ArticleVo;
import com.shishuo.cms.entity.vo.PageVo;

@Service
public class ArticleCommentService {
	@Autowired
	private ArticleCommentDao articleCommentDao;
	
	
	public ArticleComment addArticleComment(ArticleComment articleComment) {
		articleCommentDao.addArticleComment(articleComment);
		return articleComment;
	}

	public void delArticleComment(long id) {
		articleCommentDao.delArticleCommentById(id);
	}
	public List<ArticleCommentVo> getAllListByArticleId(
			@Param("articleId") long articleId,
			@Param("offset") long offset, @Param("rows") long rows) {
		return articleCommentDao.getArticleCommentListByArticleId(articleId, offset, rows);
	}
	public PageVo<ArticleCommentVo> getPagesListByArticleId(
			@Param("articleId") long articleId,
			@Param("p") int pageNum,
			@Param("rows") int rows) {
		PageVo<ArticleCommentVo> pageVo = new PageVo<ArticleCommentVo>(pageNum);
		pageVo.setRows(rows);
		pageVo.setCount(articleCommentDao.getArticleCommentListCountByArticleId(articleId));
		List<ArticleCommentVo> list=articleCommentDao.getArticleCommentListByArticleId(articleId, pageVo.getOffset(), pageVo.getRows());
		pageVo.setList(list);
		return pageVo;
	}
	public int getAllListCountByArticleId(
			@Param("articleId") long articleId,
			@Param("offset") long offset, @Param("rows") long rows) {
		return articleCommentDao.getArticleCommentListCountByArticleId(articleId);
	}
}
